package com.example.SocialApplication.service;

import android.os.AsyncTask;
import com.example.SocialApplication.constants.URLs;
import com.example.SocialApplication.db.entity.ColorEntity;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

public class CallServiceGetColors extends AsyncTask<Void, Void, List<ColorEntity>> implements URLs {

    public CallServiceGetColors() {
    }

    @Override
    protected List<ColorEntity> doInBackground(Void... params) {
        String url = GET_COLORS_URL;
        String result = "";
        try {
            result = HttpServices.callHttpGetRequest(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        List<ColorEntity> list = null;
        if (!result.equals("")) {
            Gson gson = new Gson();
            Type listType = new TypeToken<ArrayList<ColorEntity>>(){}.getType();
            list = gson.fromJson(result, listType);
        }
        return list;
    }
}
